<template>
  <div class="test-page">
    <div class="test-container">
      <h1>🎨 二次元粉色权限提示框测试</h1>
      
      <div class="test-section">
        <h2>快速测试</h2>
        <div class="button-grid">
          <button class="test-btn primary" @click="testDefault">
            默认样式
          </button>
          
          <button class="test-btn error-401" @click="test401">
            401 登录过期
          </button>
          
          <button class="test-btn error-403" @click="test403">
            403 权限不足
          </button>
          
          <button class="test-btn error-404" @click="test404">
            404 资源不存在
          </button>
          
          <button class="test-btn error-500" @click="test500">
            500 服务器错误
          </button>
          
          <button class="test-btn custom" @click="testCustom">
            自定义消息
          </button>
        </div>
      </div>
      
      <div class="test-section">
        <h2>模拟API调用</h2>
        <div class="button-grid">
          <button class="test-btn api" @click="simulateApiError(401)">
            模拟 401 错误
          </button>
          
          <button class="test-btn api" @click="simulateApiError(403)">
            模拟 403 错误
          </button>
          
          <button class="test-btn api" @click="simulateApiError(404)">
            模拟 404 错误
          </button>
          
          <button class="test-btn api" @click="simulateApiError(500)">
            模拟 500 错误
          </button>
        </div>
      </div>
      
      <div class="test-section">
        <h2>使用组件方式</h2>
        <button class="test-btn component" @click="showComponentModal = true">
          显示组件模态框
        </button>
      </div>
      
      <div class="info-box">
        <h3>💡 提示</h3>
        <ul>
          <li>点击按钮测试不同的错误提示样式</li>
          <li>所有提示框都支持点击背景或按钮关闭</li>
          <li>提示框会自动居中显示</li>
          <li>具有平滑的动画效果</li>
        </ul>
      </div>
    </div>
    
    <!-- 组件方式使用 -->
    <PermissionDeniedModal
      v-model="showComponentModal"
      title="组件测试 (｡•́︿•̀｡)"
      message="这是直接使用组件的示例～"
      @close="handleModalClose"
    />
  </div>
</template>

<script setup>
import { ref } from 'vue'
import permissionAlert from '@/utils/permissionAlert'
import PermissionDeniedModal from '@/components/PermissionDeniedModal.vue'

const showComponentModal = ref(false)

// 测试默认样式
const testDefault = () => {
  permissionAlert.show()
}

// 测试401错误
const test401 = () => {
  permissionAlert.showByStatus(401)
}

// 测试403错误
const test403 = () => {
  permissionAlert.showByStatus(403)
}

// 测试404错误
const test404 = () => {
  permissionAlert.showByStatus(404)
}

// 测试500错误
const test500 = () => {
  permissionAlert.showByStatus(500)
}

// 测试自定义消息
const testCustom = () => {
  permissionAlert.show({
    title: '自定义标题 (｡•́︿•̀｡)',
    message: '这是一个自定义的消息内容～\n可以有多行文字哦！\n\n非常可爱的粉色风格💖',
    onClose: () => {
      console.log('自定义对话框已关闭')
    }
  })
}

// 模拟API错误
const simulateApiError = (status) => {
  const messages = {
    401: '您的登录已过期，API返回401',
    403: '您没有权限访问此API，返回403',
    404: '请求的API资源不存在，返回404',
    500: '服务器内部错误，返回500'
  }
  
  permissionAlert.showByStatus(status, messages[status])
}

// 组件关闭回调
const handleModalClose = () => {
  console.log('组件模态框已关闭')
}
</script>

<style scoped>
.test-page {
  min-height: 100vh;
  padding: 40px 20px;
  background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
}

.test-container {
  max-width: 900px;
  margin: 0 auto;
}

h1 {
  text-align: center;
  color: #FF1493;
  font-size: 32px;
  margin-bottom: 40px;
  text-shadow: 0 2px 4px rgba(255, 20, 147, 0.2);
}

.test-section {
  background: white;
  border-radius: 16px;
  padding: 30px;
  margin-bottom: 30px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
}

.test-section h2 {
  color: #FF69B4;
  font-size: 20px;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 2px solid #FFE4E1;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 15px;
}

.test-btn {
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.test-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.test-btn:active {
  transform: translateY(0);
}

.test-btn.primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.test-btn.error-401 {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.test-btn.error-403 {
  background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.test-btn.error-404 {
  background: linear-gradient(135deg, #30cfd0 0%, #330867 100%);
}

.test-btn.error-500 {
  background: linear-gradient(135deg, #a8edea 0%, #fed6e3 100%);
  color: #333;
}

.test-btn.custom {
  background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
  color: #333;
}

.test-btn.api {
  background: linear-gradient(135deg, #FFB6C1 0%, #FF69B4 100%);
}

.test-btn.component {
  background: linear-gradient(135deg, #FF1493 0%, #FF69B4 100%);
  width: 100%;
}

.info-box {
  background: linear-gradient(135deg, #FFF5F7 0%, #FFE4E8 100%);
  border-radius: 16px;
  padding: 25px;
  border: 2px solid #FFB6C1;
}

.info-box h3 {
  color: #FF1493;
  margin-bottom: 15px;
  font-size: 18px;
}

.info-box ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.info-box li {
  color: #666;
  padding: 8px 0;
  padding-left: 25px;
  position: relative;
}

.info-box li::before {
  content: '💖';
  position: absolute;
  left: 0;
}

@media (max-width: 768px) {
  h1 {
    font-size: 24px;
  }
  
  .test-section {
    padding: 20px;
  }
  
  .button-grid {
    grid-template-columns: 1fr;
  }
}
</style>
